"""
@version:python3
@author:ll
@file:04-QWidget-父子关系-案例.py
@time:2022/2/10 22:09
"""
from PyQt5.Qt import *


class Window(QWidget):
    def __init__(self):
        super().__init__()
        self.setWindowTitle("")
        self.resize(500, 500)
        self.setup_ui()

    def setup_ui(self):  # 添加子控件以及子控件的配置操作
        pass

    def mousePressEvent(self, evt):
        local_x = evt.x()
        local_y = evt.y()
        # print("被点击了", local_x, local_y)
        sub_widget = self.childAt(local_x, local_y)
        if sub_widget:
            sub_widget.setStyleSheet("background-color:red")





# class Label(QLabel):
#     def mousePressEvent(self, evt):
#         self.setStyleSheet("background-color:red")


if __name__ == "__main__":
    import sys

    app = QApplication(sys.argv)
    window = Window()
    for i in range(1,11):
        label = QLabel(window)
        label.setText("标签" + str(i))
        label.move(40*i,40*i)




    window.show()

    sys.exit(app.exec_())
